<template>
	<view class="videoList">
		<view v-for="(item, index) in list" :key='index'>
		  <video class="video" :poster="url+item.back_picture" :vid="item.vid" :autoplay="false" :playerid="'myVideo_' + item.id"></video>
		  <view class='middle'>
			<view class='left'>{{item.title}}</view>
			<view class='right'>
			  <button class='box btn' open-type="share">
				<view class="share"></view>
			  </button>
			  <view class="box">
				  <view class="collect" @click="myfavourite(item)">
					  <image :src="item.user_status ? '/static/collect_act.png' : '/static/collect.png'"></image>
				  </view>
				  <text>{{item.collect_count}}</text>
			  </view>
			  <view class="box">
				  <view class="comment">
					  <image src="/static/edit.png"></image>
				  </view>
				  <text>{{item.comment_count}}</text>
			  </view>
			</view>
		  </view>
		  <view class='msg'>
			<view class="msg_content">
			  <view class='left'>{{item.info}}</view>
			</view>
		  </view>
		</view>
	</view>
</template>

<script>
	import { VideoList, uVideoList, CollectVideo } from '@/common/api'
	import { requestURL } from '@/common/utils/config'
	import { mapGetters } from 'vuex'
	export default {
		data () {
			return {
				list: [],
				url: requestURL
			}
		},
		created() {
			this.getList()
		},
		computed: {
			...mapGetters([
				'userInfo'
			])
		},
		watch: {
			userInfo(newValue, oldValue) {
				this.getList()
			}
		},
		methods: {
			getList () { // 视频列表
				if (this.userInfo) {
					uVideoList().then(res => {
						this.list = res.data
					})
				} else {
					VideoList().then(res => {
						this.list = res
					})
				}
			},
			myfavourite (item) { // 点赞
			    const data = {
					type: 2,
					data_type: 1,
					collect_id: item.id
				}
				uni.showLoading({ mask: true })
				CollectVideo(data).then(res => {
					uni.hideLoading()
					if (!res.code) {
						if (item.user_status) {
							item.user_status = 0
							item.collect_count--
						} else {
							item.user_status = 1
							item.collect_count++
						}
					}
				})
			}
		}
	}
</script>

<style lang="less" scoped>
@import '../../../common/styles/variables.less';	
.videoList {
	.video { width: 100%;display: block; }
	& > view { background-color:white;margin-bottom: 15upx }
	.middle {
		padding: 15upx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		.border-bottom;
		.left {
			font-size: @title;
			font-weight: 600;
			color: #607D8B;
		}
		.img {
			height: 50upx;
			width: 50upx;
			margin-left: 10upx;
		}
		.right {
			display: flex;
			align-items: center;
			.box {
				display: flex;
				margin-right: 20upx;
				font-size: 32upx;
				align-items: center;
				color:#878088;
				&.btn {
					border: 0 none;
					background:transparent;
				}
				&:last-of-type { margin: 0; }
				.share {
					width: 50upx;
					height: 50upx;			
				}
				.collect {
					width: 45upx;
					height: 45upx;
					margin-right: 10upx;
					image {
						width: 100%;
						height: 100%;
						display: block;
					}
				}
				.comment {
					width: 45upx;
					height: 45upx;
					padding-right: 10upx;
					image {
						width: 100%;
						height: 100%;
						display: block;
					}
				}
			}
			.btn {
				&::after {
					border: none
				}
			}
		}
	}
	.msg {
	  padding: 15upx 20upx;
	  color: #999;
	  .msg_title {
		  display: flex;
		  align-items: center;
		  .img {
			height: 30upx;
			width: 30upx;
			margin: 0 20upx;  
		  }
	  }
	  .msg_content {
		  display: flex;
		  justify-content: space-between;
		  .left { 
			  font-size: @minSize;
			  line-height: 44upx;
			  .twoLine(2)
			  }
	  }
	}
}	
</style>
